package com.book.controller;

import com.book.adapter.Login3rdAdapter;
import com.book.pojo.BusinessLaunch;
import com.book.pojo.UserInfo;
import com.book.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description:TODO
 * @date 2023/10/23 21:56
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private Login3rdAdapter adapter;


    @PostMapping("/login")
    public String login(String account,String password){
        return userService.login(account,password);
    }

    /**
     * gitee回调接口,并且返回code和state信息
     * @param code
     * @param state
     * @return
     */
    @PostMapping("/gitee")
    public String gitee(String code,String state){
        return adapter.loginByGitee(code,state);
    }

    @PostMapping("/register")
    public String register(@RequestBody UserInfo info){
        return userService.register(info);
    }


    @PostMapping("/business/launch")
    public List<BusinessLaunch> launchBusiness(@RequestParam("city") String targetCity, @RequestParam("sex") String targetSex, @RequestParam("product") String targetProduct){
        return userService.launchBusiness(targetCity,targetSex,targetProduct);
    }

}
